
{***********************************************************}
{                                                           }
{      Luxena Class Library                                 }
{                                                           }
{      Variant Utilities                                    }
{                                                           }
{      Copyright (c) 2001-2008 Luxena Software Company      }
{      http://www.luxena.com                                }
{      e-mail: support@luxena.com                           }
{                                                           }
{***********************************************************}

unit LXVariants;

{$I lx.inc}

interface

{$IFNDEF D6}
const
  varShortInt = $0010;
  varWord     = $0012;
  varLongWord = $0013;
  varInt64    = $0014;

type
  TVarType    = Word;
{$ENDIF}

function LXVarType(const Value: Variant): TVarType;
function LXVarIsClear(const Value: Variant): Boolean;
function LXVarIsNull(const Value: Variant): Boolean;
function LXVarIsArray(const Value: Variant): Boolean;
function LXVarAsType(const Value: Variant; VarType: TVarType): Variant;
function LXVarToStr(const Value: Variant): string;
function LXVarArrayOf(const Values: array of Variant): Variant;
function LXVarArrayDimCount(const Value: Variant): Integer;
function LXVarArrayLowBound(const Value: Variant; Dim: Integer): Integer;
function LXVarArrayHighBound(const Value: Variant; Dim: Integer): Integer;
function LXVarArrayLock(const Value: Variant): Pointer;
procedure LXVarArrayUnlock(const Value: Variant);

var
  LXUnassigned: Variant;
  LXNull: Variant;

implementation

{$IFDEF D6}
uses Variants;
{$ENDIF}

function LXVarType(const Value: Variant): TVarType;
begin
  Result := VarType(Value);
end;

function LXVarIsClear(const Value: Variant): Boolean;
begin
{$IFDEF D6}
  Result := VarIsClear(Value);
{$ELSE}
  with TVarData(Value) do
    Result := (VType = varEmpty) or
      (((VType = varDispatch) or (VType = varUnknown)) and (VDispatch = nil));
{$ENDIF}
end;

function LXVarIsNull(const Value: Variant): Boolean;
begin
  Result := VarIsNull(Value);
end;

function LXVarIsArray(const Value: Variant): Boolean;
begin
  Result := VarIsArray(Value);
end;

function LXVarAsType(const Value: Variant; VarType: TVarType): Variant;
begin
  Result := VarAsType(Value, VarType);
end;

function LXVarToStr(const Value: Variant): string;
begin
  Result := VarToStr(Value);
end;

function LXVarArrayOf(const Values: array of Variant): Variant;
begin
  Result := VarArrayOf(Values);
end;

function LXVarArrayDimCount(const Value: Variant): Integer;
begin
  Result := VarArrayDimCount(Value);
end;

function LXVarArrayLowBound(const Value: Variant; Dim: Integer): Integer;
begin
  Result := VarArrayLowBound(Value, Dim);
end;

function LXVarArrayHighBound(const Value: Variant; Dim: Integer): Integer;
begin
  Result := VarArrayHighBound(Value, Dim);
end;

function LXVarArrayLock(const Value: Variant): Pointer;
begin
  Result := LXVarArrayLock(Value);
end;

procedure LXVarArrayUnlock(const Value: Variant);
begin
  VarArrayUnlock(Value);
end;


initialization
  LXUnassigned := Unassigned;
  LXNull := Null;

end.